<html>
<head> 
	<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="https://cdn.bootcss.com/jquery-mobile/1.4.5/jquery.mobile.min.css">
    <script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/jquery-mobile/1.4.5/jquery.mobile.min.js"></script>
    <script src="https://cdn.bootcss.com/require.js/2.3.6/require.min.js"></script>
    <title>物性工具</title> 

<script>
	function toRound(value){
		var value2;
		if (value > 1000000){
			value2 = value.toFixed(0);
		}
		else if (value > 100000){
			value2 = value.toFixed(1);
		}
		else if (value > 10000){
			value2 = value.toFixed(2);
		}
		else if (value > 1000){
			value2 = value.toFixed(3);
		}
		else if (value > 100){
			value2 = value.toFixed(4);
		}
		else if (value > 10){
			value2 = value.toFixed(5);
		}
		else if (value > 1){
			value2 = value.toFixed(6);
		}
		else{
			value2 = value.toFixed(7);
		}
		return value2
	}

	// 定义转换函数：Pa 到 Torr
	function paToTorr(pascal) {
	  return pascal * 0.00750062;
	}

	// 定义转换函数：Torr 到 Pa
	function torrToPa(torr) {
	  return torr / 0.00750062;
	}

	// 定义转换函数：Pa 到 mbar
	function paToMbar(pascal) {
	  return pascal * 0.01;
	}

	// 定义转换函数：mbar 到 Pa
	function mbarToPa(mbar) {
	  return mbar / 0.01;
	}

	// 定义转换函数：Pa 到 hPa
	function paToHpa(pascal) {
	  return pascal * 0.01;
	}

	// 定义转换函数：hPa 到 Pa
	function hpaToPa(hectopascal) {
	  return hectopascal / 0.01;
	}
	// 计算流量
	function calcPressure(){
		// 获取参数
		var v1_value = document.getElementById('v1').value;
		var v1_unit = $('[name="v1_unit"]:checked').val();
		var v2_value = document.getElementById('v2').value;
		var v2_unit = $('[name="v2_unit"]:checked').val();
		var p = ''
		var p2 = ''

		switch (v1_unit) {
			case 'torr':
				p = torrToPa(v1_value);
				break;
			case 'hpa':
				p = hpaToPa(v1_value);
				break;
			case 'mbar':
				p = mbarToPa(v1_value);
				break;
			case 'pa':
				p = v1_value / 1;
				break;
		}

		switch (v2_unit) {
			case 'torr':
				p2 = paToTorr(p);
				break;
			case 'hpa':
				p2 = paToHpa(p);
				break;
			case 'mbar':
				p2 = paToMbar(p);
				break;
			case 'pa':
				p2 = p / 1;
				break;
		}

		document.getElementById('v2').value = toRound(p2)

	}

</script>
<style>
.ui-input{
  float:left;
  width: 100px; 
}
.ui-input>div{
    display: inline-block;
    line-height: 26px;
    height: 26px;
}

.ui-lable{
   float:left;
   line-height:26px; 
   width: 60px; 
}

.ui-lable.ui-lable-left{
   line-height:36px;	
}

.ui-unit{
   float:left;
   line-height:20px; 
}

</style>

</head>
<body>
    <div data-role="page" id="pageone">
		<div data-role="header" data-position="fixed">
			<h1 id="header-device-detail">真空单位换算</h1>
			<a href="javascript:document.location='./flow.html'" class="ui-btn ui-btn-right ui-alt-icon ui-nodisc-icon ui-corner-all ui-btn-icon-notext ui-icon-back"></a>
		</div>

		<div data-role="main" class="ui-content">
		
		<form action="">
			<div class="ui-grid-a">
				<div class="ui-lable ui-lable-left">
				    <label><b>真空1：</b></label>
			    </div>
				<div class="ui-input">
				    <input type="text" width="10px" name="v1" id="v1" data-mini="true" onchange="calcPressure()" value="101325">
				</div>
				<fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
					<label for="v1_pa"> Pa </label>
					<input type="radio" name="v1_unit" id="v1_pa" onchange="calcPressure()" value="pa" checked>
					<label for="v1_torr">Torr</label>
					<input type="radio" name="v1_unit" id="v1_torr" onchange="calcPressure()" value="torr">
					<label for="v1_mbar">mbar</label>
					<input type="radio" name="v1_unit" id="v1_mbar" onchange="calcPressure()" value="mbar">
					<label for="v1_hpa">hPa</label>
					<input type="radio" name="v1_unit" id="v1_hpa" onchange="calcPressure()" value="hpa">
				</fieldset>
			</div>

			<div class="ui-grid-a">
				<div class="ui-lable ui-lable-left">
				    <label><b> </b></label>
			    </div>
				<div class="ui-lable ui-lable-left">
				    <label><b>&nbsp;&nbsp;&nbsp;&nbsp;=</b></label>
			    </div>
				<div class="ui-lable ui-lable-left">
				    <label><b> </b></label>
			    </div>
			</div>


			<div class="ui-grid-a">
				<div class="ui-lable ui-lable-left">
				    <label><b>真空2：</b></label>
			    </div>
				<div class="ui-input">
				    <input type="text" width="10px" name="v2" id="v2" data-mini="true" onchange="calcPressure()" value="101325" onfocus="this.blur();">
				</div>
			    <fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
					<label for="v2_pa"> Pa </label>
					<input type="radio" name="v2_unit" id="v2_pa" onchange="calcPressure()" value="pa" checked>
					<label for="v2_torr">Torr</label>
					<input type="radio" name="v2_unit" id="v2_torr" onchange="calcPressure()" value="torr">
					<label for="v2_mbar">mbar</label>
					<input type="radio" name="v2_unit" id="v2_mbar" onchange="calcPressure()" value="mbar">
					<label for="v2_hpa">hPa</label>
					<input type="radio" name="v2_unit" id="v2_hpa" onchange="calcPressure()" value="hpa">
				</fieldset>
			</div>

		</form>
		<li data-role="fieldcontain">
			<div id="message">
				<p>* 输入真空值1，选择单位换算成真空值2</p>
			</div>
		</li>
	    </div>
	</div>
</body>
</html>